home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 January: Mac OS SDK / Dev.CD Jan 99 SDK2.toast / Development Kits / TEC 1.4 / SampleCode / UnicodeHub / LDynamicArray.h < prev    next >
Encoding:
Text File  |  1998-09-25  |  2.6 KB  |  116 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    LDynamicArray.h               ©1994-1996 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //
  5. //    An ordered collection of fixed-size items. Positions in the Array are
  6. //    one-based--the first item is at index 1.
  7.  
  8. #ifndef _H_LDynamicArray
  9. #define _H_LDynamicArray
  10. #pragma once
  11.  
  12. #include <PP_Prefix.h>
  13.  
  14. typedef        Int32    ArrayIndexT;
  15.  
  16.  
  17. class    LDynamicArray {
  18. public:
  19.     enum                { index_Bad        = 0,
  20.                           index_First    = 1,
  21.                           index_Last    = 0x7FFFFFFF };
  22.  
  23.                         LDynamicArray(
  24.                                 Uint32            inItemSize,
  25.                                 Uint32            inSpaces = 0);
  26.                         LDynamicArray(
  27.                                 Uint32            inItemSize,
  28.                                 Handle            inItemsHandle);
  29.     virtual                ~LDynamicArray();
  30.                                 
  31.     Boolean                ValidIndex(
  32.                                 ArrayIndexT        &inIndex) const;
  33.     
  34.     Uint32                GetItemSize() const        { return mItemSize; }
  35.     Uint32                GetCount() const        { return mItemCount; }
  36.  
  37.     virtual void        InsertItemsAt(
  38.                                 Uint32            inCount,
  39.                                 ArrayIndexT        inAtIndex,
  40.                                 const void        *inItem);
  41.  
  42.     virtual void        RemoveItemsAt(
  43.                                 Uint32            inCount,
  44.                                 ArrayIndexT        inAtIndex);
  45.     
  46.     virtual Boolean        FetchItemAt(
  47.                                 ArrayIndexT        inAtIndex,
  48.                                 void            *outItem) const;
  49.                         
  50.     virtual void        AssignItemsAt(
  51.                                 Uint32            inCount,
  52.                                 ArrayIndexT        inAtIndex,
  53.                                 const void        *inValue);
  54.  
  55.     virtual void        SetItemAt(
  56.                                 ArrayIndexT        inAtIndex,
  57.                                 const void        *inItem);
  58.     
  59.     virtual void        SwapItems(
  60.                                 ArrayIndexT        inIndexA,
  61.                                 ArrayIndexT        inIndexB);
  62.     virtual void        MoveItem(
  63.                                 ArrayIndexT        inFromIndex,
  64.                                 ArrayIndexT        inToIndex);
  65.     
  66.     virtual ArrayIndexT    FetchIndexOf(
  67.                                 const void        *inItem) const;
  68.                         
  69.     virtual void        Remove(
  70.                                 const void        *inItem);
  71.     
  72.     void                Lock();
  73.     void                Unlock();
  74.     virtual void*        GetItemPtr(
  75.                                 ArrayIndexT        inAtIndex) const;
  76.                                 
  77.     void                AllocateSpace(
  78.                                 Uint32            inSpaces);
  79.                             
  80. protected:
  81.     Uint32                mItemSize;
  82.     Uint32                mItemCount;
  83.     Uint32                mAllocation;
  84.     Handle                mItemsH;
  85.     Uint32                mLockCount;
  86.  
  87.     void                PeekItem(
  88.                                 ArrayIndexT        inAtIndex,
  89.                                 void            *outItem) const
  90.                         {
  91.                             ::BlockMoveData(GetItemPtr(inAtIndex), outItem,
  92.                                                 mItemSize);
  93.                         }
  94.  
  95.     void                PokeItem(
  96.                                 ArrayIndexT        inAtIndex,
  97.                                 const void        *inItem)
  98.                         {
  99.                             ::BlockMoveData(inItem, GetItemPtr(inAtIndex),
  100.                                                 mItemSize);
  101.                         }
  102.  
  103.     void                ShiftItems(
  104.                                 ArrayIndexT        inStartPos,
  105.                                 ArrayIndexT        inEndPos,
  106.                                 ArrayIndexT        inDestPos);
  107. };
  108.  
  109. #ifndef _H_LList
  110. const    Int32    arrayIndex_Bad        = 0;
  111. const    Int32    arrayIndex_First    = 1;
  112. const    Int32    arrayIndex_Last        = 0x7FFFFFFF;
  113. #endif
  114.  
  115. #endif
  116.